﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace SharedGenomics.Domain
{
    /// <summary>
    /// Base class for all analysis results - each instance corresponds to a single line in a job output file. Subclasses correspond to lines for particular
    /// job output files.
    /// </summary>
    public abstract class AnalysisResult
    {
        public IEnumerable<string> GetSnpPropertyNames()
        {
            return this.GetSnpProperties().Select(p => p.Name);
        }

        public IEnumerable<string> GetSnpPropertyValues()
        {
            return this.GetSnpProperties()
                .Select(p => p.GetValue(this, null) as string)
                .Where(val => val != null);
        }

        private IEnumerable<PropertyInfo> GetSnpProperties()
        {
            return this.GetType()
                .GetProperties()
                .Where(p => p.GetCustomAttributes(typeof(SnpAttribute), true).Length > 0);
        }

        [SnpAttribute]
        [AnalysisResultColumn("SNP")]
        [ColumnDisplay("SNP", Position = 0)]
        public virtual string SnpName { get; set; }

        [AnalysisResultColumn(DefaultOnParseFailed = double.NaN)]
        [ColumnDisplay("P", Position = 100)]
        public virtual double P { get; set; }

        [AnalysisResultColumn(DefaultOnParseFailed = double.NaN)]
        [ColumnDisplay("Emp1", Position = 101)]
        public virtual double Emp1 { get; set; }

        [AnalysisResultColumn(DefaultOnParseFailed = double.NaN)]
        [ColumnDisplay("Emp2", Position = 102)]
        public virtual double Emp2 { get; set; }
    }
}
